<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />


<html>
  <head>
	<title>退货入库</title>
	

  <script type="text/javascript">
  	 $(function() {
		    $("#queryForm").validate(); 
			$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
       });
  		var datatable_content ;
	  	$(function(){
			initTable();
		});
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			  "bServerSide":true,
	           "sAjaxSource":'${ctx}/v2/returnGood/page',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true, 
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": "oldExpress"},
	             	 {"mData": "returnExpress"},
	             	 {"mData": "sku"},
	             	 {"mData": "oldOrderNo"},
	             	 {"mData": "status"},
	             	 {"mData": "createTime"},
	             	 {"mData": "inbillCode"},
	             	 {"mData": "register"},
	             	 {"mData": "id"},
	             ],
	             
	             "aoColumnDefs":[
	            	 {"aTargets":[5],
	             	    "mRender":function(data,display,row){
	             			return data == 0 ? "否" :
	             				   data == 1 ? "是" : "";
	                 	 }
	             		},
	             	 {"aTargets":[6],
	             	    "mRender":function(data,display,row){
	             			return new Date(row.createTime.time).Format("yyyy-MM-dd hh:mm:ss");
	                 	 }
	             		},
	             	 {"aTargets": [9],
		              "mRender": function (data, display, row) {
		                    var rs = "";
		                    if(row.status == '0'){
		                    	rs= "<a href=\"${ctx}/v2/returnGood/updateRg/"+data+"\" class=\"btn btn-primary\">修改</a>"
		                    	+"<button onclick=\"deleteRg('"+row.id+"')\" type=\"button\" class=\"btn btn-delete\">删除</button>"
		                    	+"<button onclick=\"match('"+row.id+"')\" type=\"button\" class=\"btn btn-danger\">匹配</button>";
		                    }else if(row.status == '1'){
			        			
						   	}
						    return rs;
			           }
		            },
	             ]
			});
		}
		var filterParam = {};
		function callback( sSource, aoData, fnCallback ) {
		 var formParam = $("#queryForm").serializeArray();
			for(var n in filterParam){
				formParam.push(filterParam[n]);
			}
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });   
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
		
		function match(id){
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/returnGood/match',
				data : {id : id},
				dataType : 'json',
				success : function(data){
					if(data == true){
						alert("匹配成功");
						location.href="${ctx}/v2/returnGood/returnGoodList";
					}else{
						alert("匹配失败");
					}
				}
			});
		
		}
		function deleteRg(id){
			if(confirm("确定删除吗？"))
   			 {
   			 $.ajax({
				type : 'post',
				url : '${ctx}/v2/returnGood/deleteReturnGood',
				data : {id : id},
				success : function(data){
					$("#queryForm").submit();
				}
			});
			
  			 }
		  	  else
		    {
		       return false;
		    }
			
		}
  </script>
  </head>

  <body>
  <section class="content">
   <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			    
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
    <form class="form-search" id="queryForm" method="post" style="margin-top: 10px;">
		
		<div class="form-group row">
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">来源订单号:</span>
						<input class="form-control"  type="text" id="_oldOrderNo" name="_EQ_oldOrderNo" value="${param._EQ_oldOrderNo}" />
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">退货快递单号:</span>
						<input class="form-control" type="text" id="_returnExpress" name="_EQ_returnExpress" value="${param._EQ_returnExpress}" />
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">原快递单号:</span>
						<input class="form-control"  type="text" id="_oldExpress" name="_EQ_oldExpress" value="${param._EQ_oldExpress}" />
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">SKU:</span>
						<input class="form-control"  type="text" class="input-medium" id="_sku" name="_EQ_sku" value="${param._EQ_sku}" />
					</div>
				</div>
		</div>
		<div class="form-group row">
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">是否匹配:</span>
						<select class="form-control" id="_status" name="_EQ_status" value="${param._EQ_status}">
							<option value=""></option>
							<option value='0'>否</option>
							<option value='1'>是</option>
						</select>	
					</div>
				</div>
				<div class="col-sm-6">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">创建日期:</span>
					 	<input type="text" name="_GTE_createTime" id="_fromDate"  class="form-control"  value="${param._GTE_createTime}" /> 
					 	<span class="input-group-text">至</span>
					 	<input type="text" name="_LT_createTime" id="_toDate" class="form-control" value="${param._LT_createTime}" /> 
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<button class="btn btn-primary" type="button" style="margin-left: 10px;" onclick="query()">搜索</button>
						<a  role="button" class="btn btn-info" href="${ctx}/v2/returnGood/returnGood_create">创建退货入库</a>
					</div>
				</div>
	</div>
		</form>
	  </div>
	 </div>
	</div>
  </div>
	<c:if test="${not empty message}">
			<div id="message" class="alert alert-success alert-dismissable">
				<i class="fa fa-check"></i>
				<button data-dismiss="alert" class="close">
					×
				</button>
				${message}
			</div>
		</c:if>
	<div class="form-group row"  style="margin-top: 5px;">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed"  style="margin-top: 0px;">
		<thead>
			<tr>
				<th style="width: 20px;">序号</th>
				<th style="width: 120px;">原快递单号</th>
				<th style="width: 120px;">退货快递单号</th>
				<th style="width: 110px;">SKU</th>
				<th style="width: 120px;">来源订单号/原始单号</th>
				<th style="width: 40px;">是否匹配</th>
				<th style="width: 100px;">创建时间</th>
				<th style="width: 120px;">入库单号</th>
				<th style="width: 40px;">创建人</th>
				<th style="width: 60px;">操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	</div>
		</div>
		</div>
		</div>
	</section>
  </body>
</html>
